package com.jt.controller;


import com.jt.pojo.ItemCat;
import com.jt.service.ItemCatService;
import com.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class ItemCatController {
    @Autowired
    private ItemCatService itemCatService;

    //查询3级商品分类信息
    //@GetMapping("/itemCat/findItemCatList/{level}")
    public SysResult findItemCatList(@PathVariable Integer level){
        List<ItemCat> list=itemCatService.findItemCatList(level);
        return SysResult.success("服务器调用成功", list);
    }
    //修改商品状态
   //@PutMapping("/itemCat/status/{id}/{status}")
    public SysResult updateStatusById(ItemCat itemCat){
        itemCatService.updateStatusById(itemCat);
        return SysResult.success();
   }
   //@PostMapping("/itemCat/saveItemCat")
    public SysResult saveItemCat(@RequestBody ItemCat itemCat){
        int rows= itemCatService.saveItemCat(itemCat);
        return SysResult.success("服务器调用成功","新增分类数为："+rows);
   }
    /**
     * 查询三级分类的信息
     * url：/itemCat/findItemCatList/{level}
     * 参数：level
     * 返回值：SysResult对象(list)
     */

    @GetMapping("/itemCat/findItemCatList/{level}")
    public SysResult findItemCatListMP(@PathVariable Integer level){
        List<ItemCat> list=itemCatService.findItemCatListMP(level);
        return SysResult.success(list);
    }
    /**
     * 实现商品分类新增操作
     * URL: /itemCat/saveItemCat
     * 参数:  this.itemCatForm  JSON
     * 返回值: SysResult对象
     */
    @PostMapping("/itemCat/saveItemCat")
    public SysResult saveItemCatMP(@RequestBody ItemCat itemCat){
        itemCatService.saveItemCatMP(itemCat);
        return SysResult.success();
    }
    /**
     * 需求：实现商品分类删除操作
     * 类型：delete
     * URL:/itemCat/deleteItemCat?id=xx&level=xx
     * 参数：id/level
     * 返回值：SysResult
     */
    @DeleteMapping("/itemCat/deleteItemCat")
    public SysResult deleteItemCat(ItemCat itemCat){
        itemCatService.deleteItemCat(itemCat);
        return SysResult.success();
    }

    /**
     * 需求：修改商品分类信息
     * URL：/itemCat/updateItemCat
     * 参数：表单数据  ItemCat对象
     * 返回值：SysResult对象
     */
    @PutMapping("/itemCat/updateItemCat")
    public SysResult updateItemCat(@RequestBody ItemCat itemCat){
        itemCatService.updateItemCat(itemCat);
        return SysResult.success();
    }

    /**
     * 需求：修改商品分类状态
     * URL：/itemCat/status/{id}/{status}
     * 参数：id/status
     * 返回值：SysResult
     */
    @PutMapping("/itemCat/status/{id}/{status}")
    public SysResult updateStatusByIdMP(@PathVariable Integer id,@PathVariable Boolean status){
        itemCatService.updateStatusByIdMP(id,status);
        return SysResult.success();
    }
}
